﻿Imports System.Data.SqlClient

Public Class frmPedidosConfig

    Private Sub frmPedidosConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip2.Cursor = Cursors.Hand
        ToolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System

        CargaConceptos()
        CargaProveedores()

    End Sub
    Sub CargaConceptos()
        lstConcepto.Items.Clear()


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT CNOMBREC01 FROM MGW10006 WHERE CIDDOCUM01=38"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read
            lstConcepto.Items.Add(rdBuscar("CNOMBREC01"))
        Loop

        lstConcepto.SelectedItem = BuscarStrDatoCitra("SELECT NOMBRE FROM PEDIDOSCONCEPTO")
    End Sub
    Sub CargaProveedores()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT CRAZONSO01 FROM MGW10002 WHERE CTIPOCLI01>=2 AND CESTATUS=1 ORDER BY CRAZONSO01"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read
            txtProveedor.AutoCompleteCustomSource.Add(rdBuscar("CRAZONSO01").ToString.Trim)
        Loop

        txtProveedor.Text = BuscarStrDatoCitra("SELECT NOMBRE FROM PEDIDOSPROVEEDOR")
    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        Dim Proveedor As New clsPedidosProveedor
        Dim Concepto As New clsPedidosConcepto

        Call SetSqlCitra("DELETE FROM PEDIDOSPROVEEDOR")
        Call SetSqlCitra("DELETE FROM PEDIDOSCONCEPTO")

        Proveedor.IdProveedor = BuscarIntDatoCitra("SELECT CIDCLIEN01 FROM MGW10002 WHERE CRAZONSO01='" & txtProveedor.Text & "'")
        Proveedor.Codigo = BuscarStrDatoCitra("SELECT CCODIGOC01 FROM MGW10002 WHERE CRAZONSO01='" & txtProveedor.Text & "'")
        Proveedor.Nombre = txtProveedor.Text

        Concepto.idConcepto = BuscarIntDatoCitra("SELECT CIDCONCE01 FROM MGW10006 WHERE CNOMBREC01='" & lstConcepto.Text & "'")
        Concepto.Codigo = BuscarStrDatoCitra("SELECT CCODIGOC01 FROM MGW10006 WHERE CNOMBREC01='" & lstConcepto.Text & "'")
        Concepto.Nombre = lstConcepto.Text

        Proveedor.Insertar()
        Concepto.Insertar()

        Close()

    End Sub
End Class